import random,re
from test_read import *
words = map(lambda x:re.sub(r'\W+', '', x[:-1]), open("/usr/share/dict/american-english").readlines())
num_comp_tests = 1
num_read_tests = 3
f1 = None
f2 = None
path1 = "%s/small.csv" % mountdir
path2 =  "%s/small.csv" % csvdir

def init():
    global f1, f2
    f1 =  open(path1, "rw+")
    f2 = open(path2, "rw+")
    


def get_str(size):
    return " ".join([words[random.randint(0, len(words) -1)] for i in xrange(size)])

def readline(n):
    for i in xrange(n):
        f1.readline()
        f2.readline()

def truncate():
    n1 = f1.tell()
    n2 = f2.tell()
    if n1 != n2:
        print "two file possitions differ,n1=%d,n2=%d" % (n1, n2)
        exit()
    f1.truncate()
    f2.truncate()

def writeline(n):
    for i in xrange(n):
        s = "%d,%d,%d,%d,%s,%s,%s,%s" % (i, random.randint(0,1 << 20), random.randint(0,1 << 20),
                                          random.randint(0,1 << 20), get_str(3), get_str(3), get_str(3), get_str(3))
        print >>f1, s
        print >>f2, s
         
def close():
    f1.close()
    f2.close()

def test():
    for i in xrange(num_comp_tests):
        init()
        readline(10)
        truncate()
        writeline(4)
        close()
        compare_files(path1, path2, num_read_tests)

if __name__== '__main__':
    test()